function PopOver(pContent,pShow,pStyleClass){



	/******Private***************/

	var content=pContent;
	var isShowing=pShow;
	var container;
	var header;
	var content;
	var styleClass=pStyleClass;
	(function init(){
		console.log("[DEBUG] New PopOver created with content : " + content );
		createPopOverHtmlStructure();



	})();


	function createPopOverHtmlStructure (){
		container = document.createElement("div");
		header = document.createElement("div");
		content = document.createElement("div");

		container.id="PopOver";
		header.id="header";
		content.id="content";

		container.appendChild(header);
		container.appendChild(content);

		$(container).addClass(styleClass);
		$(container).css("display","none");
		
		
	}

	function getLocation(element){
		var offset = $(element).offset();

		var x = (offset.top - $(element).height()/2) -  ($(container).height()/2 - 20);
		var y = offset.left + $(element).width();

	 
		return [x,y];
	}

	function initLocation(location){

		if(location.length < 2 ){
			
			location = getLocation(location);
		}
	 
		$(container).css("top",(location[0]));		
		$(container).css("left",(location[1]));		


		console.log("[DEBUG] showing at location : " + location);
		
	}

	
	/****************************/


	/********Public**************/

	this.setContent = function(contentId){

		$(contentId).clone().css("display","block").prependTo($(content));
		 
	};
	this.setHeader = function(pHeader){

		$(header).append(pHeader);
		 
	};
	this.getContent = function(){return content;};


	this.show = function (element , orientation){

		document.body.appendChild(container);

		initLocation(element);

		$(container).css("display","block");
	};
	this.hide = function (){
		// $(container).hide("slow", function () {
		// 	document.body.removeChild(container);
		// });
		document.body.removeChild(container);
		
	};

	/****************************/
}


function initPopOver(){
	$(".popover").each(function(index) {
		var po;
		$(this).mouseover(function(){
			po = new PopOver();
			po.setHeader("Dr. Burghardt Zimny");
			po.setContent("#dcont");
			po.show($(this),"right");
		});

		$(this).mouseout(function(){
			 	 
			po.hide($(this));
		});
	});
	
}

$(document).ready(initPopOver);
